package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.app.util.UploadUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/images")
public class ImagesController {
    @PostMapping
    public Map upload(MultipartFile file){
        HashMap<String, Object> map = new HashMap<>();
        try {
            String imgUrl = UploadUtil.upload(file,UploadUtil.PATH + "/upload");
            map.put("status",1);
            map.put("url",imgUrl);
        } catch (Exception e) {
            map.put("status",0);
            map.put("msg","上传失败");
        }
        return map;
    }


}
